package com.DFB.controller;


import com.DFB.common.model.Result;
import com.DFB.pojo.Change;
import com.DFB.pojo.Property;
import com.DFB.service.ChangeService;
import com.DFB.service.PropertyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 商品加料表 前端控制器
 * </p>
 *
 * @author DFB
 * @since 2023-09-11
 */
@Slf4j
@RestController
@RequestMapping("/change")
public class ChangeController {
    @Autowired
    ChangeService changeService;

    // 增
    @PostMapping("/addChange")
    public Result add(@RequestBody Change change){
        log.info("add:{}",change);
        changeService.save(change);
        return Result.success();
    }

    // 查
    @GetMapping("/propertyList")
    public Result<List<Change>> get(){
        log.info("get");
        List<Change> list = changeService.list();
        return Result.success(list);
    }

    @GetMapping("/changeList/{id}")
    public Result<Change> getbyid(@PathVariable Long id){
        log.info("getbyid:{}",id);
        Change change = changeService.getById(id);
        return Result.success(change);
    }


    // 删
    @DeleteMapping("/delChange/{id}")
    public Result delete(@PathVariable Long id){
        log.info("delete:{}",id);
        changeService.removeById(id);
        return Result.success();
    }

    // 改
    @PutMapping("/updateChange")
    public Result update(@RequestBody Change change){
        log.info("update:{}",change);
        changeService.updateById(change);
        return Result.success();
    }
}

